package com.example.financechain.config;



import com.example.financechain.interceptor.Corsinterceptor;
import com.example.financechain.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 拦截器配置
 * public api/v1/pub/
 * private api/v1/pri
 *
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    Corsinterceptor corsinterceptor(){
        return new Corsinterceptor();
    }

    @Bean
    LoginInterceptor loginInterceptor(){
        return  new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截全部路径，这个跨域要放在最上面
        registry.addInterceptor(corsinterceptor()).addPathPatterns("/**");
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/private/**");

    }


}
